#pragma once
#include <iostream>
#include <pthread.h>
#include <utility>
//RAII风格的加锁方式
struct Rmtx
{
public:
    Rmtx(pthread_mutex_t &mtx)
        : _mtx(mtx)
    {
        pthread_mutex_lock(&_mtx);
        std::cout << "已上锁" << std::endl;
    }
    ~Rmtx()
    {
        pthread_mutex_unlock(&_mtx);
        std::cout << "已解锁" << std::endl;
    }

private:
    pthread_mutex_t &_mtx;
};